<?php
$class = get_class($model);
Yii::app()->clientScript->registerScript('gii.crud', "
$('#{$class}_controller').change(function(){
	$(this).data('changed', $(this).val() != '');
});
$('#{$class}_model').bind('keyup change', function(){
	var controller = $('#{$class}_controller');
	if (!controller.data('changed'))
	{
		var id = new String($(this).val().match(/\\w*$/));
		if (id.length > 0)
		{
			id = id.substring(0, 1).toLowerCase() + id.substring(1);
		}
		controller.val(id);
	}
});
");
?>
<h1>Web App Theme Crud Generator</h1>
<p>This generator generates a controller and views that implement CRUD operations for the specified data model.</p>
<?php
$form = $this->beginWidget('CCodeForm', array(
    'model' => $model,
        ));
?>
<div class="row">
    <?php echo $form->labelEx($model, 'moduleID'); ?>
    <?php echo $form->textField($model, 'moduleID', array('size' => 65)); ?>
    <div class="tooltip">
        Module ID is case-sensitive. It should only contain word characters.
        The generated module class will be named after the module ID.
        For example, a module ID <code>forum</code> will generate the module class
        <code>ForumModule</code>.
    </div>
    <?php echo $form->error($model, 'moduleID'); ?>
</div>
<div class="checkbox_row">
    <?php echo $form->labelEx($model, 'tables'); ?>
    <?php
    $tablenames = Yii::app()->db->schema->tableNames;
    $removeNames = array('authitem', 'authitemchild', 'authassignment');
    $data = array();
    foreach ($tablenames as $tbName) {
        if (!in_array($tbName, $removeNames))
            $data[$tbName] = $tbName;
    }
    echo $form->checkBoxList($model, 'tables', $data, array(
        'template' => "{input} {label}<br/>",
        'separator' => '',
        'labelOptions' => array('style' => 'display: inline'),
    ));
    ?>
    <?php echo $form->error($model, 'tables'); ?>
</div>
<div class="row sticky">
    <?php echo $form->labelEx($model, 'baseControllerClass'); ?>
    <?php echo $form->textField($model, 'baseControllerClass', array('size' => 65)); ?>
    <div class="tooltip">
        This is the class that the new CRUD controller class will extend from.
        Please make sure the class exists and can be autoloaded.
    </div>
    <?php echo $form->error($model, 'baseControllerClass'); ?>
</div>
<div class="row">
    <?php echo $form->labelEx($model, 'generateComponents'); ?>
    <?php echo $form->checkBox($model, 'generateComponents'); ?>
    <div class="tooltip">
        Whether additional components and widgets that override default one should be generated.
    </div>
    <?php echo $form->error($model, 'generateComponents'); ?>
</div>
<div class="row sticky">
    <?php echo $form->labelEx($model, 'layoutPrefix'); ?>
    <?php echo $form->textField($model, 'layoutPrefix', array('size' => 65)); ?>
    <div class="tooltip">
        This refers to the directory that the new layout file should be generated under.
        It should be specified in the form of a path alias relatively to the base layouts directory, for example, <code>admin.ext</code>.
    </div>
    <?php echo $form->error($model, 'layoutPrefix'); ?>
</div>
<div class="row">
    <?php echo $form->labelEx($model, 'generateLayouts'); ?>
    <?php echo $form->checkBox($model, 'generateLayouts'); ?>
    <div class="tooltip">
        Whether layouts should be generated.
    </div>
    <?php echo $form->error($model, 'generateLayouts'); ?>
</div>
<div class="row sticky">
    <?php echo $form->labelEx($model, 'theme'); ?>
    <?php echo $form->dropDownList($model, 'theme', $model->getThemes(), array('style' => 'width: 420px')); ?>
    <div class="tooltip">
        Please select which theme should be used to generate the layout.
    </div>
    <?php echo $form->error($model, 'theme'); ?>
</div>
<?php $this->endWidget(); ?>
